import { constantRoutes, asyncRoutes } from '@/router/index'

const state = {
  router: []
}

const mutations = {
  getRouter(state, router) {
    state.router = [...constantRoutes, ...router]
  }
}

const actions = {
  filterRouter(store, menus) {
    const routers = asyncRoutes.filter(item => {
      return menus.indexOf(item.name) !== -1
    })
    store.commit('getRouter', routers)
    return routers
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
